package com.hxh.component.business.utils;

import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hxh.component.business.R;
import com.hxh.component.business.common.DropDownDialog;
import com.hxh.component.business.ui.face.main.LoadingActivity;
import com.hxh.component.business.utils.Constant;
import com.hxh.component.ui.alertview.OnItemClickListener;

/**
 * des:自定义弹窗样式
 *
 * @author fuchengxiang
 * @version 1.0
 * @date 2019/11/27
 */

public class popWindowUtil {



    /**
     * 提示弹窗（仅有确定按钮）
     * @param context
     */
    private static DropDownDialog mDialog;
    public static void showDialog(Context context,String title,String content) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_sure, null, false);

        TextView tv_title = view.findViewById(R.id.tv_title);
        TextView tv_content = view.findViewById(R.id.tv_content);
        TextView tv_cancle = view.findViewById(R.id.tv_cancle);

        tv_title.setText(title);
        tv_content.setText(content);

        if (null != mDialog && mDialog.isShowing()){
            return;
        }

        mDialog =  new DropDownDialog(context, view);

        tv_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDialog.cancel();
            }
        });

        mDialog.setCanceledOnTouchOutside(true);
        mDialog.setCancelable(true);
        Window dialogWindow = mDialog.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.CENTER);
        lp.x = 0;// dialog窗口 X坐标
        lp.y = 0; // dialog窗口 Y坐标
        dialogWindow.setAttributes(lp);
        mDialog.showDialog();
    }

    /**
     * 单按钮提示弹窗可监听点击事件
     * @param context
     * @param title
     * @param content
     * @param lis
     */
    public static void showDialogWithListener(Context context, String title, String content, final String btn_name
            , final OnItemClickListener lis) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_sure, null, false);

        TextView tv_title = view.findViewById(R.id.tv_title);
        TextView tv_content = view.findViewById(R.id.tv_content);
        TextView tv_cancle = view.findViewById(R.id.tv_cancle);

        tv_title.setText(title);
        tv_content.setText(content);
        tv_cancle.setText(btn_name);

        if (null != mDialog && mDialog.isShowing()){
            return;
        }

        mDialog =  new DropDownDialog(context, view);

        tv_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                lis.onItemClick(btn_name,0);
                mDialog.cancel();
            }
        });

        mDialog.setCanceledOnTouchOutside(false);
        mDialog.setCancelable(false);
        Window dialogWindow = mDialog.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.CENTER);
        lp.x = 0;// dialog窗口 X坐标
        lp.y = 0; // dialog窗口 Y坐标
        dialogWindow.setAttributes(lp);
        mDialog.showDialog();
    }

}
